import datetime
import random
from concurrent.futures import ThreadPoolExecutor

import mysql.connector

if 2 > 1:
    print('true')
mydb = mysql.connector.connect(
    host="119.29.254.80",
    user="root",
    passwd="123456",
    database="test",
    auth_plugin='mysql_native_password'
)

my_cursor = mydb.cursor()
def insert_many():
    val = []
    j = 0
    while j <= 9999:
        val.append((''.join(random.sample(
            ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f',
             'e',
             'd', 'c', 'b', 'a'], 12)),
                    "address:" + ''.join(random.sample(
                        ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h',
                         'g', 'f',
                         'e', 'd', 'c', 'b', 'a'], 12))))
        j += 1
    my_cursor.executemany(sql, val)
    mydb.commit()
    return 'finished'
threadPool = ThreadPoolExecutor(max_workers=16)

sql = "INSERT INTO user (name, phone) VALUES (%s, %s)"
i = 0
while i <= 9999:
    future = threadPool.submit(insert_many(), i, i + 1)
    i += 1
    print(i, '    ', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
threadPool.shutdown(wait=True)
print(my_cursor.rowcount*10000, "record inserted.")